import { getToken } from '@/untails/mytoken'
import request from '@/untails/request.js'
export const userLogin =(data)=>{
  return request({
      method:'POST',
      url:'/login',
      data:data
  })
}
export const register =(data)=>{
  return request({
      method:'POST',
      url:'/register',
      data:data
  })

}
export const userDetail =(id)=>{
  return request({
      method:'GET',
      url:`/user/${id}`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const userFile =(file)=>{
  return request({
      method:'POST',
      url:`/upload`,
      data:file,
      headers:{
        Authorization :getToken()
      }
  })

}
export const userUpdate  =({id,...data})=>{
  return request({
      method:'POST',
      url:`/user_update/${id}`,
      data:data,
      headers:{
        Authorization :getToken()
      }
  })

}
//获取用户关注列表
export const getUserFollows=()=>{
  return request({
      method:'GET',
      url:`/user_follows`,
      headers:{
        Authorization :getToken()
      }
  })

}
//根据id添加关注
export const addUserFollowsById =(id)=>{
  return request({
      method:'GET',
      url:`/user_follows/${id}`,
      headers:{
        Authorization :getToken()
      }
  })

}
//取消关注
export const removeFollowsById =(id)=>{
  return request({
      method:'GET',
      url:`/user_unfollow/${id}`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const getCategory = () => {
  return request({
    method: 'GET',
    url: `/category`,
    headers: {
      Authorization: getToken(),
    },
  })
}

export const getPostlist  =(params)=>{
  return request({
      method:'GET',
      url:`/post`,
      params:params,
      headers:{
        Authorization :getToken()
      }
  })

}
export const getStarList  =()=>{
  return request({
      method:'GET',
      url:`/user_star`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const getPostById  =(id)=>{
  return request({
      method:'GET',
      url:`/post/${id}`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const updatePostLikeById   =(id)=>{
  return request({
      method:'GET',
      url:`/post_like/${id}`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const removeUserFollowsById   =(id)=>{
  return request({
      method:'GET',
      url:`/user_unfollow/${id}`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const getPostCommentById    =(id)=>{
  return request({
      method:'GET',
      url:`/post_comment/${id}`,
  })

}
export const addPostComment   =({id,...data})=>{
  return request({
      method:'POST',
      url:`/post_comment/${id}`,
      data:data,
      headers:{
        Authorization :getToken()
      }
  })

}
export const getUserComment    =()=>{
  return request({
      method:'GET',
      url:`/user_comments/`,
      headers:{
        Authorization :getToken()
      }
  })

}
export const getPostsearch    =(params)=>{
  return request({
      method:'GET',
      url:`/post_search`,
      params:params
  })

}